home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT1-5 / RDDEC.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  1.5 KB  |  31 lines

  1. ;
  2. ;       Program RdDec
  3. ;
  4. .model  small                   ; small memory model - one segment only
  5. .stack                          ; stack of default size
  6. .data                           ; this starts data segment
  7. UnsWord dw      0               ; number to be output
  8. Ten     dw      10              ; constant for obtaining decimal digits
  9. .code                           ; this starts code segments
  10. .startup                        ; this initializes segment registers
  11. NextCh: mov     ah,01           ; function 01h - keyboard input
  12.     int     21h             ; DOS service call
  13.     cmp     al,0            ; special character?
  14.     jne     NotSpec         ; if not - process character
  15.     int     21h             ; read code of special character
  16.     jmp     FinProg         ; finish program
  17. NotSpec:cmp     al,'0'          ; compare character read to "0" (number?)
  18.     jb      FinProg         ; if not, don't process
  19.     cmp     al,'9'          ; compare character read to "9" (number?)
  20.     ja      FinProg         ; if not, don't process 
  21. ProcNum:sub     al,30h          ; convert character to number
  22.     mov     bl,al           ; copy character read into BX
  23.     mov     ax,UnsWord      ; hex number into AX
  24.     mul     Ten             ; one decimal position to the left
  25.     mov     UnsWord,ax      ; store result back into memory
  26.     add     UnsWord,bx      ; add current hex digit
  27.     jmp     NextCh          ; read next character
  28. FinProg:mov     ax,4C00h        ; function 4Ch - terminate process
  29.     int     21h             ; DOS service call
  30.     end     
  31.